package com.wyp168.leetcode;

/**
 * @ClassName FinalPrices
 * @Description TODO
 * @Author wyp168
 * @Date 2022/9/1 08:41
 */
public class FinalPrices {
    public static void main(String[] args) {
        int[] prices = {10};
        FinalPrices finalPrices = new FinalPrices();
        int[] res = finalPrices.finalPrices(prices);
        for (int re : res) {
            System.out.println(re);
        }
    }

    public int[] finalPrices(int[] prices) {
        int length = prices.length;
        //定义一个数组，长度为prices数组的长度，用来封装最终价格
        int[] result = new int[length];
        if (length == 1) {
            result[0] = prices[0];
            return result;
        }
        for (int i = 0; i < length; i++) {
            if (i == length - 1) {
                result[i] = prices[length - 1];
            }
            for (int j = i + 1; j < length; j++) {
                if (prices[j] <= prices[i]) { //可以折扣
                    result[i] = prices[i] - prices[j];
                    break;
                }
                if (j == length - 1) {
                    result[i] = prices[i];
                }
            }
        }
        return result;

    }
}
